home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MyAEGetData.p < prev    next >
Encoding:
Text File  |  1994-02-04  |  2.8 KB  |  93 lines  |  [TEXT/PJMM]

  1. unit MyAEGetData;
  2.  
  3. interface
  4.  
  5.     procedure InitAEGetData (GetSelectionProc: ProcPtr);
  6. { function GetSelectionProc(var reply:AppleEvent):OSErr; }
  7.     procedure FinishAEGetData;
  8.  
  9. implementation
  10.  
  11.     uses
  12.         AERegistry, AEObjects;
  13.  
  14.     const
  15.         MaxPropLevel = 2; { or whatever number of levels you want to support }
  16.  
  17.     type
  18.         propArray = array[1..MaxPropLevel] of DescType;
  19.  
  20.     function CallGetSelection (var reply: AppleEvent; proc: ProcPtr): OSErr;
  21.     inline
  22.         $205F, $4E90;
  23.  
  24.     var
  25.         getdata: ProcPtr;
  26.  
  27.     function PropertyOf (theSpec: AERecord; var propLevel: integer; var properties: propArray): boolean;
  28.         var
  29.             objSpec: AERecord;
  30.             typ, t, prop: DescType;
  31.             size: longint;
  32.             key: AEKeyword;
  33.             err: OSErr;
  34.     begin
  35.         PropertyOf := false; { we don't know this is a property yet }
  36.         if propLevel = 0 then begin { 0 means the Apple Event }
  37.             key := keyDirectObject;
  38.         end
  39.         else begin
  40.             key := keyAEContainer;
  41.         end;
  42.         if AEGetKeyDesc(theSpec, key, typeAERecord, objSpec) = noErr then begin
  43.             if (AEGetKeyPtr(objSpec, keyAEDesiredClass, typeType, typ, @t, 4, size) = noErr) & (t = cProperty) then begin
  44.                 if (AEGetKeyPtr(objSpec, keyAEKeyForm, typeEnumerated, typ, @t, 4, size) = NoErr) & (t = formPropertyID) then begin { this is redundunt, won't hurt to make sure }
  45.                     if AEGetKeyPtr(objSpec, keyAEKeyData, typeType, typ, @prop, 4, size) = NoErr then begin { which of property? }
  46.                         propLevel := propLevel + 1;
  47.                         properties[propLevel] := prop;
  48.                         if AESizeOfKeyDesc(objSpec, keyAEContainer, typ, size) = NoErr then begin { property of what }
  49.                             if typ = typeNull then begin { prop of application, we are done }
  50.                                 PropertyOf := true;
  51.                             end
  52.                             else if typ = typeObjectSpecifier then begin { from another object specifer }
  53.                                 if propLevel < MaxPropLevel then { only do it if we have not reach max level }
  54.                                     PropertyOf := PropertyOf(objSpec, propLevel, properties); { go down 1 level }
  55.                             end; { else it is an error }
  56.                         end;
  57.                     end;
  58.                 end;
  59.             end;
  60.             err := AEDisposeDesc(objSpec);
  61.         end;
  62.     end;
  63.  
  64.     function MyGetDataHandler (event, reply: AppleEvent; theRefcon: longint): OSErr;
  65.         var
  66.             err: OSErr;
  67.             propLevel: integer;
  68.             properties: propArray;
  69.     begin
  70.         err := errAENoSuchObject;
  71.         propLevel := 0; { 0 means we are passing in an Apple Event }
  72.         if PropertyOf(event, propLevel, properties) & (propLevel = 2) then begin
  73.             if (properties[1] = pContents) & (properties[2] = pSelection) then begin { it is content of selection }
  74.                 err := CallGetSelection(reply, getdata);
  75. { do your thing and put the result in the reply }
  76.             end;
  77.         end;
  78.         MyGetDataHandler := err;
  79.     end;
  80.  
  81.     procedure InitAEGetData (GetSelectionProc: ProcPtr);
  82.         var
  83.             junk: OSErr;
  84.     begin
  85.         getdata := GetSelectionProc;
  86.         junk := AEInstallEventHandler(kAECoreSuite, kAEGetData, @MyGetDataHandler, 0, false);
  87.     end;
  88.  
  89.     procedure FinishAEGetData;
  90.     begin
  91.     end;
  92.  
  93. end.